<%--
   help
   Copyright (c) 2013 ISPERP
   Version : 1.0.0
 --%>
<%@ tag language="java" pageEncoding="UTF-8"
	deferredSyntaxAllowedAsLiteral="false" trimDirectiveWhitespaces="true"%>

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="isperp" uri="/WEB-INF/tlds/isperp.tld"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ attribute name="relationId" required="true" type="java.lang.String"
	description="relationId"%>
<%@ attribute name="changeId" required="false" type="java.lang.String"
	description="changeId"%>
<%@ attribute name="relationType" required="true"
	type="java.lang.String" description="relationType"%>
<%@ attribute name="viewOnly" required="false" type="java.lang.Boolean"
	description="viewOnly"%>
<%@ attribute name="countLabel" required="false" type="java.lang.String"
	description="countLabel"%>
<%@ attribute name="projectId" required="false" type="java.lang.String"
	description="projectId"%>
<%@ attribute name="keyWord" required="false" type="java.lang.String"
	description="keyWord"%>
<%@ attribute name="crShowToolbar" required="false"
	type="java.lang.Boolean" description="keyWord"%>

<c:choose>
	<c:when test="${empty countLabel}">
		<c:set value="" var="crLoadComplete"></c:set>
	</c:when>
	<c:otherwise>
		<c:set
			value="$('#${countLabel }').text( ciUseRelationGrid.jqGrid.getGridParam('records'));"
			var="crLoadComplete"></c:set>


	</c:otherwise>
</c:choose>


<c:choose>
	<c:when test="${viewOnly eq true }">
		<c:set value="" var="crDeleteUrl"></c:set>
		<c:set value="false" var="crShowToolbar"></c:set>
	</c:when>

	<c:otherwise>
		<c:set value="configuration/ciUseRelation/delete" var="crDeleteUrl"></c:set>
		<c:set value="${crShowToolbar eq false?false:true }"
			var="crShowToolbar"></c:set>
	</c:otherwise>

</c:choose>

<input type="hidden" id="hidKeyword" value="${keyWord }">

<isperp:grid
	url="configuration/ciUseRelation/listDetail?relationId=${relationId }"
	gridId="ciUseRelationGrid" cusFormatterActions="true" height="auto"
	showSearchbar="false" showPager="false" rownumbers="false"
	showToolbar="${crShowToolbar }" actionsWidth="80"
	ondbClickRowEvent="ciUseRelationGridView(rowid)"
	loadComplete="${crLoadComplete }"
	cusActions="actionUsedGrid(rowObject);" cusDeleteUrl="${crDeleteUrl }">

	<jsp:attribute name="toolbar">
	<isperp:toolbar id="iconToolbar">
		<isperp:button text="添加关联资产项" icon="icon-plus" type="button"
				cssClass="button  nui-mainbtn" onclick="selectCi();"></isperp:button>
	</isperp:toolbar>
	</jsp:attribute>
	<jsp:body>
	<isperp:column name="id" title="id" hidden="true"></isperp:column>
	<isperp:column name="ci_id" title="ci_id" hidden="true"></isperp:column>
	<isperp:column name="code" title="编号" width="80"></isperp:column>
	<isperp:column name="name" title="资产名称" width="150"></isperp:column>
	<isperp:column name="conf_category_name" title="资产类型" width="150"></isperp:column>
	<isperp:column name="status" title="状态" width="60"></isperp:column>
	</jsp:body>
</isperp:grid>

<isperp:ciListSelector id="ciSelector"
	afterSelected="ciUseRelationGrid.reload();checkIfChangeFlow(ids);"
	relationType="${relationType }" relationId="${relationId }"
	listUrl="configuration/ciUseRelation/listCi"
	saveUrl="configuration/ciUseRelation/saveWithCi"></isperp:ciListSelector>

<script type="text/javascript">
	function checkIfChangeFlow(ids) {
		if ($("#newChangeSelectCi").val() == "true") {
			createChangeCiList(ids);
		} else {
			ciUseRelationGrid.reload();
		}
	}
	function actionUsedGrid(rowObject) {

		var actions = isperp.createGridAction({
			title : "资产履历",
			iconCls : "icon-view",
			onclick : "openCiView('" + rowObject.ci_id + "');"
		});

		return actions;
	}

	function ciUseRelationGridView(rowid) {

		var ciId = ciUseRelationGrid.getRowData(rowid).ci_id;

		openCiView(ciId);
	}

	function openCiView(ciId) {

		var hidKeyword = $("#hidKeyword").val();

		hidKeyword = hidKeyword.replace(/[\ |\~|\`|\!|\@|\#|\$|\%|\^|\&|\*|\(|\)|\-|\_|\+|\=|\||\\|\[|\]|\{|\}|\;|\:|\"|\'|\,|\<|\.|\>|\/|\?]/g, "");

		isperp.openDialog({
			title : "查看资产履历",
			contentUrl : "configuration/ci/edit?id=" + ciId + "&keyword=" + hidKeyword + "&readonly=${readonly }"
		});

	}
	function openCiEdit(ciId) {
		isperp.openDialog({
			title : "编辑资产",
			contentUrl : "configuration/ci/edit??changeId=${changeId}&id=" + ciId
		});

	}

	function checkSelectedCi() {

		var reccount = ciUseRelationGrid.jqGrid.getGridParam("reccount");
		if (reccount == 0) {
			isperp.errorAlert("请添加关联资产！");
			return false;
		}
		return true;
	}
</script>